import 'package:flutter/material.dart';

class MyDrawer extends StatefulWidget {
  const MyDrawer({Key? key}) : super(key: key);

  @override
  _MyDrawerState createState() => _MyDrawerState();
}

class _MyDrawerState extends State<MyDrawer> {
  final Widget drawHeader = const UserAccountsDrawerHeader(
    accountName: Text('志远'),
    accountEmail: Text('shizhiyuanya@qq.com'),
    currentAccountPicture: CircleAvatar(
      backgroundImage: AssetImage('images/user.jpg'),
    ),
  );

  final Widget drawFooted = Container(
    padding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
    decoration: BoxDecoration(
      border: Border(top: BorderSide(width: 1.0, color: Colors.black)),
    ),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        ElevatedButton(
          onPressed: (){},
          child: const Text('退出登录'),
          style: ButtonStyle(
            backgroundColor: MaterialStateProperty.all<Color>(Colors.transparent),
            overlayColor: MaterialStateProperty.all<Color>(Colors.transparent),
          ),

        ),
        ElevatedButton(
          onPressed: (){},
          child: const Text('切换账号')
        )
      ],
    ),
  );

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        children: [
          drawHeader,
          Expanded(
            flex: 1,
            child: ListView.builder(
              padding: const EdgeInsets.all(0),
              itemCount: 20,
              itemBuilder: (BuildContext context, index) {
                return Column(
                  children: [
                    ListTile(
                      title: Text('喜欢你${index+1}'),
                      leading: const Icon(Icons.favorite),
                      onTap: () {
                        Navigator.pop(context);
                      },
                    ),
                    const Divider( // 分割线
                      color: Colors.grey,
                      height: 1.0,
                      thickness: 1.0,
                      indent: 10.0,
                      endIndent: 10.0,
                    ),
                  ],
                );
              }
            ),
          ),
          drawFooted
        ],
      ),
    );
  }
}
